<template>
	<view class="center">
		<view class="card">
			<xbd-image-title title="近一年招投标项目数量">
				<template>
					<view  >
						<text style="font-size: 56rpx; font-family: DIN, DIN-Bold; font-weight: 700;color: #000623;margin-right: 10rpx;">
							{{count}}
						</text>
						个
					</view>
				</template>
			</xbd-image-title>
			<view class="charts">
				<chart-line-two :chartData="pressChart"></chart-line-two>
			</view>
		</view>
		<view class="card">
			<xbd-image-title title="近一年招投标占比分析">
			</xbd-image-title>
			<view class="charts" v-if="hackReset">
				<chart-ring-four v-if="is_show" :chartData="securityAlarm"></chart-ring-four>
				<xbd-zwnz v-else marginTop='200'></xbd-zwnz>
			</view>
		</view>
		<view class="card">
			<xbd-image-title title="近一年招投标合格率分析">
			</xbd-image-title>
			<view class="charts" v-if="hackReset">
				<chart-ring-unit v-if="is_show2" :chartData="securityAlarm2"></chart-ring-unit>
				<xbd-zwnz v-else marginTop='200'></xbd-zwnz>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		Prevention
	} from '@/api/index.js';
	export default {
		data() {
			return {
				is_show:false,
				is_show2:false,
				hackReset:true,
				count:'',
				pressChart: {
					name: ['合格', '整改通过'],
					unit: ['个', '个'],
					color: ['#48BC7C','#1EA9FB'],
					x: 'x',
					y: ['y', 's'],
					data: [
					]
				},
				securityAlarm: {
					unit: '次',
					data: [{
							grade: "重大决策",
							num: 0,
							const: 'const'
						},
						{
							grade: "重要人事",
							num: 0,
							const: 'const'
						},
						{
							grade: "重大项目",
							num: 0,
							const: 'const'
						},
					]
				},
				securityAlarm2: {
					unit: '次',
					data: [{
							grade: "项目合格",
							num: 0,
							const: 'const'
						},
						{
							grade: "整改通过",
							num: 0,
							const: 'const'
						},
					]
				},
			};
		},
		methods: {
			// js 浮点数计算会出现不准确的时候  需要调用此函数进行浮点数计算
			accMul(arg1,arg2){
			  var m=0,s1=arg1.toString(),s2=arg2.toString();
			  try{m+=s1.split(".")[1].length}catch(e){}
			  try{m+=s2.split(".")[1].length}catch(e){}
			  return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
			},
			async init() {
				const res = await Prevention.getBidChart()
				this.pressChart.data = res.data.line.chart
				this.count = res.data.line.total
				this.securityAlarm.data = res.data.first_pie.map(item => {
					let o = {
						grade: item.x,
						num: this.accMul(item.y,100),
						const: 'const'
					}
					return o
				})
				console.log(this.securityAlarm,'this.securityAlarm')
				this.securityAlarm2.data[0].num=res.data.sencod_pie.yes
				this.securityAlarm2.data[1].num=res.data.sencod_pie.not
				if(this.securityAlarm.data[0].num !==0 || this.securityAlarm.data[1].num!==0 || this.securityAlarm.data[2].num!==0 ){
					this.is_show = true
				}
				if(this.securityAlarm2.data[0].num !==0 || this.securityAlarm2.data[1].num!==0 ){
					this.is_show2 = true
				}
				
				// this.qualified = res.data.chart
				// 重新渲染dom节点  防止绘图出错
				          this.hackReset = false
				          this.$nextTick(()=>{
				            this.hackReset = true
				          })
				console.log(res,'res2')
			}
		},
		created() {
			console.log(0/0,'阿松大去')
			this.init()
		}
	}
</script>

<style lang="scss" scoped>
	.center {
		padding: 32rpx;

		.card {
			padding: 32rpx;
			background-color: #FFFFFF;
			margin-bottom: 32rpx;
			.charts {
				height: 500rpx;
			}
			.type{
				width: 600rpx;
				display: flex;
				justify-content: space-between;
				font-size: 26rpx;
				font-family: PingFang SC, PingFang SC-Regular;
				font-weight: 400;
				color: #8890a5;
			}
		}
	}
</style>
